const express = require('express')
var fs = require('fs');//读取文件用
const app = express();

// 允许跨域访问
app.all('*', function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1');
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});

app.get('/data', (req, response) => {
    fs.readFile('./data.json', function (err, data) {
        if (!err) {
            response.writeHead(200, { "Content-Type": "application/json" });
            response.end(data);
        } else {
            throw err;
        }
    })
    response.status(200);

})

app.listen(3000, () => { console.log("启动成功") });

